package com.longge;

public class SumOddLengthSubarrays {

    public int sumOddLengthSubarrays(int[] arr) {

        int len = 1;
        int ans = 0;
        while (len <= arr.length) {
            for (int i = 0; i < arr.length; i++) {
                ans += sumSubArr(i, len, arr);
            }
            len += 2;
        }
        return ans;
    }

    private int sumSubArr(int i, int len, int[] arr) {
        if (i + len > arr.length) return 0;
        int res = 0;
        for (int j = i; j < i + len; j++) {
            res += arr[j];
        }
        return res;
    }

    public static void main(String[] args) {
        new SumOddLengthSubarrays().sumOddLengthSubarrays(new int[]{10,11,12});
    }

}
